package com.shujia.core

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

object Demo5flatMap {
  def main(args: Array[String]): Unit = {

    val conf = new SparkConf()
    conf.setMaster("local")
    conf.setAppName("flatMap算子演示")
    val context = new SparkContext(conf)
    //====================================================
    val linesRDD: RDD[String] = context.textFile("spark/data/words.txt")

    /**
     *  flatMap算子：将RDD中的数据一条一条的取出传递给后面的函数，函数的返回值必须是一个集合。最后会将集合展开构成一个新的RDD
     */
    val wordsRDD: RDD[String] = linesRDD.flatMap((line: String) => line.split("\\|"))

    wordsRDD.foreach(println)
  }
}
